<template>
  <div class="">
   <Header title="地址管理"></Header>
   <van-address-list
        v-model="data.chosenAddressId"
        :list="data.list"
        default-tag-text="默认"
        @add="onAdd"
        @edit="onEdit"
        @select="onSelect"
      />
  </div>
</template>

<script  setup>
import Header from '@/components/Header.vue'
import { reactive,onMounted } from 'vue';
import { useStore } from 'vuex';
let store=useStore()
let data=reactive({
  list:[],
  chosenAddressId:''
})
const init=()=>{
  data.list=store.state.Cart.userAddress.map((item)=>{
        return{   
        name:item.name,
        id:item.id,
        tel:item.tel,
        address:item.province+item.city+item.county+item.addressDetail,
        isDefault:item.isDefault,
        areaCode:item.areaCode
      }
    }
)
  
}
const onSelect =()=>{

}
const onSelect123=()=>{
  store.state.Cart.userAddress.forEach(item => {
     return data.chosenAddressId=item.id
  });

}


onMounted(()=>{
  init()
  onSelect123();
})


import { useRouter } from 'vue-router';
let router=useRouter()
  


    const onAdd = () => {
      router.push({
      path:'/addressedit',
      query:{
        type:'add'
      }
     })
    };
    
    const onEdit = (item) =>{
     router.push({
      path:'/addressedit',
      query:{
        id:item.id
      }
     })
    };
</script>

<style scoped>
</style>
